package com.evildog.workspace.system.application.feign;

import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.system.api.feign.UserClient;
import com.evildog.workspace.system.api.vo.UserVO;
import com.evildog.workspace.system.application.bo.UserBO;
import com.evildog.workspace.system.application.convert.UserConvert;
import com.evildog.workspace.system.application.service.UserService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * User feign client
 * 账户表
 * </p>
 *
 * @author evildog
 * @since 2020-07-18
 */
@RestController
@RequestMapping(UserClient.API_PREFIX)
@AllArgsConstructor
@Api(tags = "user相关接口")
public class UserClientImpl implements UserClient {

    private UserService userService;

    @Override
    @GetMapping("/login")
    public Result<UserVO> getUser(@RequestParam String account, @RequestParam String password) {
        UserBO userBO = userService.getAccount(account, password);
        return ResultGenerator.success(UserConvert.INSTANCE.convertFeignVO(userBO));
    }

    @Override
    @GetMapping("/{userId}")
    public Result<UserVO> getUser(@PathVariable Long userId) {
        UserBO userBO = userService.getAccount(userId);
        return ResultGenerator.success(UserConvert.INSTANCE.convertFeignVO(userBO));
    }
}

